package com.aipg.rnp;

import com.aipg.common.AipgRsp;
import com.nuanshui.heatedloan.credit.pay.TransRequestCode;
import com.nuanshui.heatedloan.credit.utils.XMLConvertUtil;
import org.dom4j.Element;
import org.springframework.beans.BeanUtils;

public class XMLParseExtension {

    public static void parse(String resp,AipgRsp aipgrsp)
    {

        if(aipgrsp.getINFO().getTRX_CODE().equals(TransRequestCode.TRX_CODE_USERACCOUNT_AUTH_APPLY))
        {
            Element element=XMLConvertUtil.getElement(resp,"RNPARET");

            if(element!=null)
            {
                RNPARET item=RNPARET.parse(element);
                aipgrsp.addTrx(item);
            }
        }
        else if(aipgrsp.getINFO().getTRX_CODE().equals(TransRequestCode.TRX_CODE_USERACCOUNT_AUTH_RESEND))
        {
            Element element=XMLConvertUtil.getElement(resp,"RNPRRET");

            if(element!=null)
            {
                RNPARET item=RNPRRET.parse(element);
                RNPRRET target=new RNPRRET();
                BeanUtils.copyProperties(item,target);
                aipgrsp.addTrx(target);
            }
        }
        else if(aipgrsp.getINFO().getTRX_CODE().equals(TransRequestCode.TRX_CODE_USERACCOUNT_AUTH_VERIFY))
        {
            Element element=XMLConvertUtil.getElement(resp,"RNPCRET");

            if(element!=null)
            {
                RNPARET item=RNPRRET.parse(element);
                RNPCRET target=new RNPCRET();
                BeanUtils.copyProperties(item,target);
                aipgrsp.addTrx(target);
            }
        }
    }
}
